<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="检验单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inspectCode']" placeholder="请输入检验单号"></a-input>
        </a-form-item>
        <a-form-item label="单号名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['matproSn']" placeholder="请输入单号名称"></a-input>
        </a-form-item>
        <a-form-item label="检测阶别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inspectGrade']" placeholder="请输入检测阶别"></a-input>
        </a-form-item>
        <a-form-item label="物料料号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materielCode']" placeholder="请输入物料料号"></a-input>
        </a-form-item>
        <a-form-item label="物料名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materielName']" placeholder="请输入物料名称"></a-input>
        </a-form-item>
        <a-form-item label="物料规格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['materielGague']" placeholder="请输入物料规格"></a-input>
        </a-form-item>
        <a-form-item label="检测数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inspectNum']" placeholder="请输入检测数量"></a-input>
        </a-form-item>
        <a-form-item label="不良数量" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['badNum']" placeholder="请输入不良数量"></a-input>
        </a-form-item>
        <a-form-item label="不良率" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['badRate']" placeholder="请输入不良率"></a-input>
        </a-form-item>
        <a-form-item label="检验合格" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['inspectQualify']" :trigger-change="true" dictCode="yn" placeholder="请选择检验合格"/>
        </a-form-item>
        <a-form-item label="处理方式" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['handleWay']" placeholder="请输入处理方式"></a-input>
        </a-form-item>
        <!-- <a-form-item label="关联单号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['relatedCode']" placeholder="请输入关联单号"></a-input>
        </a-form-item> -->
        <a-form-item label="替换SN" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['replaceSn']" placeholder="请输入替换SN"></a-input>
        </a-form-item>
        <a-form-item label="维修内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['repairContent']" rows="4" placeholder="请输入维修内容"/>
        </a-form-item>
        <a-form-item label="检验员" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['inspectPerson']" placeholder="请输入检验员"></a-input>
        </a-form-item>
        <a-form-item label="审核" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['verify']" placeholder="请输入审核"></a-input>
        </a-form-item>
        <a-form-item label="受理人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['dealPerosn']" placeholder="请输入受理人"></a-input>
        </a-form-item>
        <a-form-item label="受理时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择受理时间" v-decorator="['dealTime']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="原因分析及处理措施" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['reasonAnalyze']" rows="4" placeholder="请输入原因分析及处理措施"/>
        </a-form-item>
        <a-form-item label="效果确认及描述" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-textarea v-decorator="['effectConfirm']" rows="4" placeholder="请输入效果确认及描述"/>
        </a-form-item>
        <a-form-item label="确认人" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="['confirmPerson']" placeholder="请输入确认人"></a-input>
        </a-form-item>
        <a-form-item label="确认时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择确认时间" v-decorator="['confirmTime']" :trigger-change="true" :show-time="true" date-format="YYYY-MM-DD HH:mm:ss" style="width: 100%"/>
        </a-form-item>

      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesBadnessHandleModal",
    components: { 
      JDate,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules: {
        },
        url: {
          add: "/inspect/mesBadnessHandle/add",
          edit: "/inspect/mesBadnessHandle/edit",
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'createBy','createTime','matproSn','inspectCode','inspectGrade','materielCode','materielName','materielGague','handleWay','relatedCode','replaceSn','repairContent','inspectNum','badNum','badRate','inspectQualify','inspectPerson','verify','dealPerosn','dealTime','reasonAnalyze','effectConfirm','confirmPerson','confirmTime'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'createBy','createTime','matproSn','inspectCode','inspectGrade','materielCode','materielName','materielGague','handleWay','relatedCode','replaceSn','repairContent','inspectNum','badNum','badRate','inspectQualify','inspectPerson','verify','dealPerosn','dealTime','reasonAnalyze','effectConfirm','confirmPerson','confirmTime'))
      },

      
    }
  }
</script>